<extend name="Public/base"/>

<block name="body">
    <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
    <div class="main-title">
        <h2>{$info['id']?'编辑':'新增'}轮播图</h2>
    </div>
    <form action="{:U('Plink/save')}" method="post" class="form-horizontal">
        <div class="form-item">
            <label class="item-label">图片名称<span class="check-tips">这图叫什么图啊！</span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="name" value="{$info.name}">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">图片链接<span class="check-tips">你要到哪里去？</span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="url" value="{$info.url}">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">图片上传<span class="check-tips">我要开车的那种!!!(注意同名覆盖)</span></label>
            <div class="controls">
                <div class="controls">
                    <!--图片上传-->

                    <input type="file" id="upload_picture_{$field.name}">
                    <input type="hidden" name="picname" id="cover_id_{$field.name}" value="{$data[$field['name']]}"/>
                    <!--显示图片-->
                    <div class="upload-img-box">
                        <input type="hidden" name="path"  value="{$info.path}"/>
                        <notempty name="data[$field['name']]">
                            <div class="upload-pre-item">
                                <img src="{$data[$field['name']]|get_cover='path'}"/></div>
                        </notempty>
                    </div>
                </div>
                <script type="text/javascript">
                    //上传图片
                    /* 初始化上传插件 */
                    $("#upload_picture_{$field.name}").uploadify({
                        "height"          : 30,
                        "swf"             : "__STATIC__/uploadify/uploadify.swf",
                        "fileObjName"     : "download",
                        "buttonText"      : "上传图片",
                        "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id(),'setpath'=>'PLINK_PICTURE_UPLOAD'))}",
                        "width"           : 120,
                        'removeTimeout'	  : 1,
                        'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
                        "onUploadSuccess" : uploadPicture{$field.name}
                    });
                    function uploadPicture{$field.name}(file, data){
                        var data = $.parseJSON(data);
                        var src = '';
                        if(data.status){
                            $("#cover_id_{$field.name}").val(data.id);
                            src = data.url || '__ROOT__' + data.path
                            $("#cover_id_{$field.name}").parent().find('.upload-img-box').html(
                                    '<input type="hidden" name="path"  value="__ROOT__'+data.path+'"/><div class="upload-pre-item"><img src="' + src + '"/></div>'
                            );
                        } else {
                            updateAlert(data.info);
                            setTimeout(function(){
                                $('#top-alert').find('button').click();
                                $(that).removeClass('disabled').prop('disabled',false);
                            },1500);
                        }
//                        console.log();
                    }

                </script>
            </div>
        </div>

        <div class="form-item">
            <input type="hidden" name="id" value="{$info.id|default=''}">
            <button class="btn submit-btn" id="submit" type="submit" target-form="form-horizontal">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </form>
</block>

<block name="script">
    <script type="text/javascript">
        // Think.setValue("type", {$info.type|default=0});
        // Think.setValue("group", {$info.group|default=0});
        //导航高亮
        $('.side-sub-menu').find('a[href="{:U('Plink/index')}"]').closest('li').addClass('current');
    </script>
</block>
